import { FormSchema } from "/@/components/Table"
import { isRoleExist, listMenuScheme } from "./fileConfig"
import { DescItem } from "/@/components/Description/index"
import { render } from "/@/utils/common/renderUtils"
import { rules } from "/@/utils/helper/validator"
export const columns = [
  {
    title: "业务类型",
    dataIndex: "bizType",
    helpMessage: "业务类型同时也会作为存储路径的根路径",
    width: 120,
  },

  // {
  //   title: '限制类型',
  //   dataIndex: 'fileTypeLimit',
  //   customRender: ({ text }) => {
  //     if (!text) {
  //       return ''
  //     }
  //     const data = text.split(',')
  //     return render.renderTag(data, 'green')
  //   },
  //   width: 160,
  // },

  {
    title: "限制大小",
    dataIndex: "fileSizeLimit",
    width: 80,
    customRender: ({ text }) => {
      return render.renderSpan(text + " KB")
    },
  },

  {
    title: "状态",
    dataIndex: "status",
    width: 60,
    customRender: ({ text }) => {
      let color = "red"
      if (text === "1") {
        color = "green"
      }
      return render.renderTag(render.renderDict(text, "data_use_status"), color)
    },
  },
  {
    title: "备注",
    dataIndex: "remark",
    width: 160,
  },
  {
    title: "更新时间",
    dataIndex: "updatedAt",
    width: 160,
  },
  {
    title: "更新者",
    dataIndex: "updatedBy",
    width: 120,
  },
]

export const searchFormSchema: FormSchema[] = [
  {
    field: "bizType",
    label: "业务类型",
    component: "Input",
    colProps: { span: 6 },
  },
  {
    label: "存储器",
    field: "storageType",
    component: "JDictSelectTag",
    componentProps: {
      dictType: "file_storage_type",
    },
    colProps: { span: 6 },
  },
]

export const formSchema: FormSchema[] = [
  {
    field: "id",
    label: "",
    component: "Input",
    show: false,
  },
  {
    field: "bizType",
    label: "业务类型",
    required: true,
    component: "Input",
  },
  // {
  //   field: 'bucketName',
  //   label: '存储桶',
  //   required: true,
  //   component: 'Input',
  // },
  {
    label: "限制类型",
    field: "fileTypeLimit",
    helpMessage: "为空则不限制",
    component: "JDictSelectTag",
    defaultValue: [],
    componentProps: {
      mode: "multiple",
      dictType: "file_type",
      // stringToNumber: true
    },
  },
  {
    label: "文件key模板",
    field: "fileKeyTmpl",
    component: "InputTextArea",
    helpMessage: [
      '支持的变量如下：',
      '${year}: 年份(eg: 2025)',
      '${month}: 月份(eg: 02)',
      '${day}: 天(eg: 04)',
      '${uuid}: 随机id(eg: 123)',
      '${fileName}: 文件名(eg: test.png)',
      '${loginId}: 登录id(eg: 123), 如果没有登录会生成一个随机id',
    ],
    defaultValue: "/data/${uid}/${year}/${month}/${day}/${uuid}-${fileName}",
    componentProps: {
      rows: 2,
    },
  },
  {
    label: "限制大小",
    field: "fileSizeLimit",
    helpMessage: "单位为KB",
    required: true,
    slot: "fileSizeLimit",
    component: "Input",
  },
  {
    label: "状态",
    field: "status",
    component: "JDictSelectTag",
    defaultValue: "1",
    componentProps: {
      type: "radio",
      dictType: "data_use_status",
    },
  },

  {
    label: "备注",
    field: "remark",
    component: "InputTextArea",
    componentProps: {
      placeholder: "请输入备注",
      rows: 5,
    },
  },
]

export const formDetailSchema: DescItem[] = [
  {
    field: "bizType",
    label: "业务类型",
  },
  {
    field: "fileTypeLimit",
    label: "限制类型",
    render: (curVal, data) => {
      let val = []
      if (curVal) {
        val = curVal.split(",")
      }
      return render.renderTag(val, "green")
    },
  },
  {
    field: "fileSizeLimit",
    label: "限制大小",
    render: (curVal, data) => {
      return curVal + " KB"
    },
  },
  {
    field: "status",
    label: "状态",
    render: (curVal, data) => {
      let color = "#ff7f50"
      if (curVal === "1") {
        color = "#2ecc71"
      }
      return render.renderTag(render.renderDict(curVal, "data_use_status"), color)
    },
  },
  {
    field: "createdAt",
    label: "创建时间",
  },
  {
    field: "createdBy",
    label: "创建者",
  },
  {
    field: "updatedAt",
    label: "更新时间",
  },
  {
    field: "updatedBy",
    label: "更新者",
  },
  {
    label: "备注",
    labelMinWidth: 40,
    field: "remark",
  },
]
